<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>无标题文档</title>
  <link th:href="@{/css/style.css}" rel="stylesheet" type="text/css"/>
  <script type="text/javascript" th:src="@{/js/jquery-1.12.4.js}"></script>
  <script src="https://code.highcharts.com.cn/highcharts/highcharts.js"></script>
  <script src="https://code.highcharts.com.cn/highcharts/modules/exporting.js"></script>
  <script src="https://code.highcharts.com.cn/highcharts/modules/drilldown.js"></script>
  <script src="https://img.hcharts.cn/highcharts-plugins/highcharts-zh_CN.js"></script>
</head>

<body>
<div class="place"><span>位置：</span>
  <ul class="placeul">
    <li>数据统计</li>
    <li>客户销量统计</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form id="form" th:action="@{/market/order/findPageAllFZ}" method="get">
    <input type="hidden" id="pageNum" name="pageNum" th:value="${session.pb.pageNum}"/>
    <ul class="tools">
      <li> 所属区域：
        <select name="pid">
          <option value="0">请选择省份</option>
          <option th:each="p : ${provinceList}" th:selected="${pid==p.id}" th:value="${p.id}"
                  th:text="${p.pName}">北京
          </option>
        </select>
        <input type="hidden" th:value="${cid}" name="cid"/>
        <select name="address">
          <option value="0">请选择城市</option>
        </select>
      </li>
      <script>
        $(function () {
          ajaxCid($("select[name=pid]").val());

          $("select[name=pid]").change(function () {
            ajaxCid($(this).val());
          });
        });

        function ajaxCid(pid) {
          $.ajax({
            url: "/erp/market/customer/ajaxCityPid",
            data: {"pid": pid},
            dataType: "JSON",
            success: function (city) {
              var op = "<option value='0'>请选择城市</option>";
              $.each(city, function (i, e) {
                if (e.id == $("input[name=cid]").val()) {
                  op += "<option value='" + e.id + "' selected>" + e.cname + "</option>";
                } else {
                  op += "<option value='" + e.id + "'>" + e.cname + "</option>";
                }
              });
              $("select[name=address]").html("");
              $("select[name=address]").append(op);

            }, error: function () {
              console.log("错误");
            }
          });
        }


      </script>
      <li> 客户姓名:
        <input placeholder="请输入姓名" type="text" name="customname" th:value="${customname}"/>
      </li>

      <li class="subBut" onclick="tiaoZhuan(1)"><img th:src="@{/images/t06.png}"/>查询</li>
      <li class="subBut" onclick="qingkong()"><img th:src="@{/images/t03.png}"/>重置</li>
      <script>
          function qingkong() {
              $("select[name=pid]>option:eq(0)").prop("selected",true);
              $("input[name=cid]").val("");
              $("input[name=customname]").val("");
              ajaxCid($("select[name=pid]").val());
          }
      </script>
    </ul>
    <table class="tablelist">
      <thead>
      <tr>
        <th>序号</th>
        <th>客户姓名</th>
        <th>所属区域</th>
        <th>订购单数量</th>
        <th>金额</th>
        <th>订购单明细</th>
      </tr>
      </thead>
      <tbody>
      <tr th:each="o,i :${pb.list}">
        <td th:text="${(pb.pageNum-1)*pb.pageSize+i.count}">1</td>
        <td th:text="${o.custom.customname}">王金平</td>
        <td th:text="${o.custom.city.Province.pName+''+o.custom.city.cName}">江苏南京</td>
        <td th:text="${o.totality}">5</td>
        <td th:text="'￥'+${o.totalMoney}+'万'">￥9,876,582</td>
        <td>
          <a th:href="@{'/market/order/findBydDelivery?customid='+${o.customid}}" class="tablelink">查看详情</a>
        </td>
      </tr>
      </tbody>
    </table>
    <div class="pagin">
      <div class="message">共<i class="blue" th:text="${pb.total}">1256</i>条记录，当前显示第&nbsp;<i class="blue"
                                                                                            th:text="${pb.pageNum}">2&nbsp;</i>页
      </div>
      <ul class="paginList">
        <li class="paginItem">
          <a href="javascript:void(0);" th:onclick="tiaoZhuan([[${pb.isFirstPage?1:pb.pageNum-1}]])">
            <span th:class="${pb.isFirstPage?'pagepre':'pagenxt roate'}"></span>
          </a>
        </li>

        <li class="paginItem" th:if="${1+4<=pb.pageNum}"><a th:onclick="tiaoZhuan(1)"
                                                            href="javascript:void(0);">1</a></li>
        <li class="paginItem more" th:if="${1+5<=pb.pageNum}"><a href="javascript:void(0);">...</a></li>
        <li class="paginItem" th:if="${1+3<=pb.pageNum}"><a th:onclick="tiaoZhuan([[${pb.pageNum-3}]])"
                                                            href="javascript:void(0);"
                                                            th:text="${pb.pageNum-3}">3</a></li>
        <li class="paginItem" th:if="${1+2<=pb.pageNum}"><a th:onclick="tiaoZhuan([[${pb.pageNum-2}]])"
                                                            href="javascript:void(0);"
                                                            th:text="${pb.pageNum-2}">4</a></li>
        <li class="paginItem" th:if="${1+1<=pb.pageNum}"><a th:onclick="tiaoZhuan([[${pb.pageNum-1}]])"
                                                            href="javascript:void(0);"
                                                            th:text="${pb.pageNum-1}">1</a></li>

        <li class="paginItem current"><a href="javascript:void(0);" th:text="${pb.pageNum}">2</a></li>

        <li class="paginItem" th:if="${pb.pages-1>=pb.pageNum}"><a th:onclick="tiaoZhuan([[${pb.pageNum+1}]])"
                                                                   href="javascript:void(0);"
                                                                   th:text="${pb.pageNum+1}">3</a></li>
        <li class="paginItem" th:if="${pb.pages-2>=pb.pageNum}"><a th:onclick="tiaoZhuan([[${pb.pageNum+2}]])"
                                                                   href="javascript:void(0);"
                                                                   th:text="${pb.pageNum+2}">4</a></li>
        <li class="paginItem" th:if="${pb.pages-3>=pb.pageNum}"><a th:onclick="tiaoZhuan([[${pb.pageNum+3}]])"
                                                                   href="javascript:void(0);"
                                                                   th:text="${pb.pageNum+3}">5</a></li>
        <li class="paginItem more" th:if="${pb.pages-5>=pb.pageNum}"><a href="javascript:void(0);">...</a></li>
        <li class="paginItem" th:if="${pb.pages-4>=pb.pageNum}"><a th:onclick="tiaoZhuan([[${pb.pages}]])"
                                                                   href="javascript:void(0);"
                                                                   th:text="${pb.pages}">10</a></li>

        <li class="paginItem">
          <a href="javascript:void(0);" th:onclick="tiaoZhuan([[${pb.isLastPage?pb.pages:pb.pageNum+1}]])">
            <span th:class="${pb.isLastPage?'pagepre roate ':'pagenxt '}"></span>
          </a>
        </li>
      </ul>
    </div>
  </form>
  <br/>
  <br/>
  <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
  <script>
    var data1 = [];
    var chart;
    $.ajax({
      url: "/erp/market/order/ajaxFindByCKWarehouse",
      data: {"pageNum": $("#pageNum").val()},
      dataType: "JSON",
      success: function (data) {
        var data2 = [];
        $.each(data, function (i, e) {
          console.log(e);
          var aa = new Array();
          var customname="";
          $.each(e, function (d, g) {
            aa.push([g.orderId + "", g.totalMoney]);
            customname = g.order.custom.customname;

          });
          aa = {name: customname, id: customname, data: aa};
          data2.push(aa);
        });


        chart = Highcharts.chart('container', {
          chart: {
            type: 'column'
            /*plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
            type: 'pie'*/
          },
          title: {
            text: '客户销售统计'
          },
          xAxis: {
            type: 'category'
          },
          yAxis: {
            title: {
              text: '总的销售金额(万)'
            }
          },
          legend: {
            enabled: false
          },
          plotOptions: {
            series: {
              borderWidth: 0,
              dataLabels: {
                enabled: true,
                format: '{point.y:.2f}万'
              }
            }
          },
          tooltip: {
            headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
            pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}万</b><br/>'
          },
          series: [{
            name: '客户姓名',
            colorByPoint: true,
            data: data1
          }],
          drilldown: {
            series: data2
          }
        });
      }
    });
    $(function () {
      $.ajax({
        url: "/erp/market/order/ajaxFindPageAllFZ",
        data: {"pageNum": $("#pageNum").val(),
          "customname":$("input[name=customname]").val(),
          "pid":$("select[name=pid]").val(),
          "address":$("input[name=cid]").val(),
        },
        dataType: "JSON",
        success: function (data) {
          $.each(data, function (i, e) {
            var aa = {name: e.custom.customname, y: e.totalMoney, drilldown: e.custom.customname};
            data1.push(aa);
          });
          chart.series[0].setData(data1);
        }
      });
    });
  </script>


  <script>
    function tiaoZhuan(pageNum) {
      $("#pageNum").val(pageNum);
      $("#form").submit();
    }
  </script>
</div>
<script type="text/javascript">
  $('.tablelist tbody tr:odd').addClass('odd');
</script>
</body>
</html>
